/**
 * inforcreation.com co.Ltd
 * MichaelHuang
 * 2011-12-16
 */
package com.zchat.api.connection;

import android.content.Context;

import com.zchat.api.ZChat;

/**
 * 根据连接上的网络去检测与应用服务器的连接状态
 * @author MichaelHuang
 *
 */
public class AppNet {

	private static String NET = ZChat.ZCHAT_SERVER;
	/**
	 * 选服务器
	 * @param server
	 * @return
	 */
	public static synchronized void detectLinkedNet(Context context) {
		Server server = Server.other;
		try {
			server = PingServer.getAvailableServer();
		} catch (Exception e) {
		}
		NET = Server.emnuToString(server);
		//set the read status.
		if(NET == null) {
			NET = ZChat.ZCHAT_SERVER;
			ReadStatusUtil.getInstance().setStatus(context, ReadStatus.offline);
		} else {
			ReadStatusUtil.getInstance().setStatus(context, ReadStatus.online);
		}
	}
	
	/**
	 * Get current linked net.
	 * @return
	 */
	public static String getLinkedNet() {
		return NET;
	}
}
